import {Pipe, PipeTransform} from "@angular/core";

@Pipe({
  name:'dateTimes',
})
export class DateTimesPipe implements PipeTransform{

  transform(value:any,...args:any[]):any{
      console.log(value);
    if(typeof value == "string"){
      const localTime = new Date();
      const temp = new Date(value.substring(0,19)+'+08:00');
      //获取传入时间的年月日
      let year:number = temp.getFullYear();
      let month:any = temp.getMonth()+1;
      let day:any = temp.getDate();
      let hours:number = temp.getHours();
      let minutes:number = temp.getMinutes();

      if(temp.getFullYear() !== localTime.getFullYear()){
        return year.toString() +"年" + month.toString()+"月" + day.toString()+"日";
      }else if(temp.getMonth()!==localTime.getMonth()){
        return month.toString() + "月" + day.toString() + "日";
      }
      const diffDays = localTime.getDate() - temp.getDate();
      if(diffDays == 0 ){
        return '今天' + hours.toString()+":"+ minutes.toString();
      }else if(diffDays == 1){
        return '昨天';
      }else{
        return month.toString()+"月"+day.toString()+"天";
      }
    }
  }

}
